<?php
/**
 * Created by PhpStorm.
 * User: this
 * Date: 2019/1/2
 * Time: 17:10
 */
namespace app\index\model;
use think\Model;

class Article extends Model{
    /**
     * @param $condition
     * @param string $field
     * @param int $page
     * @param string $order
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getPage($condition,$field = '*',$page = 10,$order = 'article_id,article_edit_time desc'){
        return $this->name('article')->field($field)->order($order)->where($condition)->paginate($page);
    }
    /**
     * @param $condition
     * @param string $field
     * @param string $order
     * @param integer $limit
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getList($condition,$field = '*',$order='article_add_time desc',$limit = 5){
        return $this->name('article')->field($field)->where($condition)->order($order)->limit($limit)->select();
    }

    /**
     * @param $condition
     * @param string $field
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getOne($condition,$field = '*'){
        return $this->name('article')->field($field)->where($condition)->find();
    }

    /**
     * @param $condition
     * @param $field
     * @param int $num
     * @return int|true
     * @throws \think\Exception
     */
    public function increase($condition,$field,$num=1){
        return $this->name('article')->where($condition)->setInc($field,$num);
    }
}